import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
  {
    path: '/',
     redirect:"/login"
  },
  // 登录
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  }, 
  // 首页
   {
    path: '/home',
    name: 'home',
    component: () => import('../views/home/index.vue'),
    redirect:"/home/home",
     children:[
      {
        path: 'home',
        name: 'home',
        component: () => import('../views/home/home.vue'),
      }, {
        path: 'xiang',
        name: 'xiang',
        component: () => import('../views/home/xiang.vue'),
        meta: { title: "相册管理" },
      }, {
        path: 'shang',
        name: 'shang',
        component: () => import('../views/home/shang.vue'),
        meta: { title: "商品列表" },
      }
     ]
  },
  // 商品
 {
    path: '/shang',
    name: 'shang',
    component: () => import('../views/shang/index.vue'),
    redirect:"/shang/shang",
     children:[
      {
        path: 'shang',
        name: 'shang',
        component: () => import('../views/shang/shang.vue'),
      }, {
        path: 'fen',
        name: 'fen',
        component: () => import('../views/shang/fen.vue'),
      }, {
        path: 'gui',
        name: 'gui',
        component: () => import('../views/shang/gui.vue'),
      }
     ]
  },
  // 订单
  {
    path: '/ding',
    name: 'ding',
    component: () => import('../views/ding/index.vue'),
    redirect:"/ding/ding",
     children:[
      {
        path: 'ding',
        name: 'ding',
        component: () => import('../views/ding/ding.vue'),

      }, {
        path: 'fa',
        name: 'fa',
        component: () => import('../views/ding/fa.vue'),

      }, {
        path: 'shou',
        name: 'shou',
        component: () => import('../views/ding/shou.vue'),

      }
     ]
  }
]
const router = new VueRouter({
  routes,
});
// 全局路由守卫
router.beforeEach((to, from, next) => {
  if (localStorage.getItem("token")) {
    next();
  } else {
    if (to.path == "/login") {
      next();
    } else {
      next("/login");
    }
  }
});
export default router;